package com.zzh.net;

import android.app.Activity;


import com.zzh.net.Utils.ProgressUtils;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class Helper {

    protected static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) {
        observable.subscribeOn(Schedulers.io())//子线程访问网络
                .observeOn(AndroidSchedulers.mainThread())//回调到主线程
                .subscribe(observer);
    }


    protected static <T> void setSubscribeLoading(Observable<T> observable, Observer<T> observer, Activity activity) {
        observable.subscribeOn(Schedulers.io())//子线程访问网络
                .observeOn(AndroidSchedulers.mainThread())//回调到主线程
                .compose(ProgressUtils.<T>applyProgressBar(activity))
                .subscribe(observer);
    }
}
